<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>用户搜索</title>
    <style type="text/css">
        .content {
            width: 643px;
            margin: 100px auto;
            text-align: center;
        }

        input[type='text'] {
            width: 530px;
            height: 40px;
            font-size: 14px;
        }

        input[type='button'] {
            width: 100px;
            height: 46px;
            background: #38f;
            border: 0;
            color: #fff;
            font-size: 15px
        }

        .show {
            position: absolute;
            width: 535px;
            height: 100px;
            border: 1px solid #999;
            border-top: 0;
            display: none;
        }
    </style>
</head>
<body>

    <div class="content">
        <img src="img/logo.jpg">
        <br/><br/>
        <input type="text" id="username">
        <input type="button" value="搜索一下" id="ii" >
        <div id="show" class="show">
        </div>
    </div>


    <a href="/testServlet">访问servlet</a>

    <form action="/testServlet">
         <input type="submit" value="提交">
    </form>



    <input type="button" value="惦记我" onclick="test()">

<a href="/index.jsp">访问</a>

</body>
<script src="js/jquery-3.3.1.min.js"></script>
<script>
		function test(){
		    //location.href="/testServlet";
            window.open("/testServlet");
        }
		$("#username").mousedown(function(){
		    //1.获得输入框的值
            let val = $(this).val();
            //2.发起请求，参数传递  回调函数
            $.get("/userServlet?username="+val,function(data){
                let jsonObj = JSON.parse(data);
                let  str = "";
                for(let i=0;i<jsonObj.length;i++){
                    let user = jsonObj[i];
                    str+="<div>"+user.name+"</div>";
                }
                $("#show").html(str).show();
            });
        });
</script>
</html>




